package com.service.approval.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.service.approval.localthread.ApprovalThreadLocal;
import com.service.approval.model.ApprovalInfo;
import com.service.approval.model.ProductInfo;
import com.service.approval.service.InsurancePolicyService;
import com.service.approval.service.ProductService;

@RestController
@RequestMapping("/loadbanlance/test")
public class LoadBanlanceTestController {

	
	@Autowired
	private RestTemplate restTempLate;
	
	@Autowired
	private ProductService productService;
	
	@Autowired
	private InsurancePolicyService insurancePolicyService;
	
	@RequestMapping("/product/{productCode}")
	@ResponseBody
	public String productBanlanceTest(@PathVariable(value="productCode")String productCode){
		ProductInfo productInfo = new ProductInfo();
		productInfo.setProductCode(productCode);
		ApprovalInfo approvalInfo = new ApprovalInfo(null, null, productInfo, null, null);
		ApprovalThreadLocal.set(approvalInfo);
		String result = restTempLate.getForObject("http://distributer-product-server/product/banlance/port", String.class);
		return result;
	}
	
	@RequestMapping("/product/feign/{productCode}")
	@ResponseBody
	public String productFeignBanlanceTest(@PathVariable(value="productCode")String productCode){
		ProductInfo productInfo = new ProductInfo();
		productInfo.setProductCode(productCode);
		ApprovalInfo approvalInfo = new ApprovalInfo(null, null, productInfo, null, null);
		ApprovalThreadLocal.set(approvalInfo);
		String result = productService.productBanlanceTest();
		return result;
	}
	
	@RequestMapping("/policy/{merchantNo}")
	@ResponseBody
	public String policyBanlanceTest(@PathVariable(value="merchantNo")String merchantNo){
		ApprovalInfo approvalInfo = new ApprovalInfo(merchantNo, null, null, null, null);
		ApprovalThreadLocal.set(approvalInfo);
		String result = restTempLate.getForObject("http://distributer-policy-server/policy/banlance/port", String.class);
		return result;
	}
	
	@RequestMapping("/policy/feign/{merchantNo}")
	@ResponseBody
	public String policyFeignBanlanceTest(@PathVariable(value="merchantNo")String merchantNo){
		ApprovalInfo approvalInfo = new ApprovalInfo(merchantNo, null, null, null, null);
		ApprovalThreadLocal.set(approvalInfo);
		String result = insurancePolicyService.policyBanlanceTest();
		return result;
	}
	
}
